/**
 * 位置压缩
 */
export type ZipPos = `${number}/${number}`

/**
 * 建筑记忆
 */
export type StructureCacheMemory<T = ZipPos> = {
    [StructureType in BuildableStructureConstant]?: {
        [id: string]: T
    }
}

/**
 * 建筑映射
 */
export type StructureMap<T extends StructureConstant = StructureConstant> = {
    [type in T]?: ConcreteStructure<type>[]
}

/**
 * 处理缺失建筑回调函数
 */
export type HandleMissingStructCallBack = (room: MyRoom, missingStructTypes: BuildableStructureConstant[]) => void

/**
 * 处理新增建筑回调函数
 */
export type HandleNewStructCallBack = (room: MyRoom, newStructMap: StructureMap) => void

/**
 * 注册建筑函数，返回注册后剩余的建筑数组，用于后续的函数注册
 */
export type RegisterStructure<T extends BuildableStructureConstant = BuildableStructureConstant> = (
    room: MyRoom,
    structures: ConcreteStructure<T>[],
) => ConcreteStructure<T>[]

/**
 * 扩展全局接口
 */
declare global {
    interface RoomMemory {
        structures: StructureCacheMemory
    }

    interface Room {
        // 这里不是用 Structure 而是 AnyStructure，因为 Structure是所有建筑的基类，而 AnyStructure 是所有建筑类型的联合类型
        structures: AnyStructure[]

        extension: StructureExtension[]
        rampart: StructureRampart[]
        road: StructureRoad[]
        spawn: StructureSpawn[]
        link: StructureLink[]
        constructedWall: StructureWall[]
        // storage: StructureStorage
        tower: StructureTower[]
        observer?: StructureObserver
        powerSpawn?: StructurePowerSpawn
        extractor?: StructureExtractor
        lab: StructureLab[]
        // terminal: StructureTerminal
        container: StructureContainer[]
        nuker?: StructureNuker
        factory?: StructureFactory
        keeperLair: StructureKeeperLair[]
        // controller: StructureController
        powerBank: StructurePowerBank[]
        portal: StructurePortal[]
        invaderCore: StructureInvaderCore[]
    }
}
